package com.nus.servlets;

import com.nus.beans.ProjectRemark;
import com.nus.database.ProjectsDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/2/12
 * Time: 11:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class UpdateProjectRemarkServlet extends AbstractServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String projectRemarkId = request.getParameter("projectRemarkId");
        String remark = request.getParameter("remark");

        int projectRemarkIdInt = Integer.parseInt(projectRemarkId);

        Connection connection = getUserDatabaseConnection(request);
        ProjectsDBManager projectDBManager = new ProjectsDBManager(connection);
        projectDBManager.updateProjectRemark(projectRemarkIdInt, remark);

        ProjectRemark updatedRemark = projectDBManager.getProjectRemark(projectRemarkIdInt);

        request.setAttribute("projects", updatedRemark.getProjectId());
        RequestDispatcher dispatcher = request.getRequestDispatcher("viewProjectRemarks.do");
        dispatcher.forward(request, response);
    }
}
